/**
 * 
 */
package com.demo2do.boyle.backend.service.system.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.demo2do.boyle.backend.service.system.TagService;
import com.demo2do.boyle.common.entity.system.tag.Tag;
import com.demo2do.core.persistence.GenericDaoSupport;
import com.demo2do.core.persistence.support.Filter;
import com.demo2do.core.service.impl.GenericServiceImpl;
import com.demo2do.core.web.resolver.Page;

/**
 * @author Leo
 *
 */
@Service("tagService")
public class TagServiceImpl extends GenericServiceImpl<Tag> implements TagService {

	@Autowired 
	private GenericDaoSupport genericDaoSupport;
	
	/*
	 * (non-Javadoc)
	 * @see com.demo2do.boyle.backend.service.system.TagService#count()
	 */
	public int count() {
		return genericDaoSupport.searchForInt("SELECT COUNT(1) FROM Tag");
	}
	
	/*
	 * (non-Javadoc)
	 * @see com.demo2do.boyle.backend.service.system.TagService#count(com.demo2do.core.persistence.support.Filter)
	 */
	public int count(Filter filter) {
		return genericDaoSupport.searchForInt("SELECT COUNT(1) FROM Tag " + filter.getWhereSentence(), filter.getParameters());
	}

	@SuppressWarnings("unchecked")
	public List<Tag> list(Page page) {
		List<Tag> tags = genericDaoSupport.searchForList("FROM Tag", page.getBeginIndex(), page.getMaxResultRecords());
		page.calculate(tags.size());
		return tags.size() > page.getEveryPage() ? tags.subList(0, page.getEveryPage()) : tags;
	}
	
	
}
